/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedbeans;


import Entities.Marquage;
import Entities.Modelerdp;
import SessionBeans.RdPManager;
import java.util.Date;
import Entities.Utilisateur;
import SessionBeans.MarquageManager;
import SessionBeans.Users;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.model.SelectItem;

/**
 *
 * @author Dell
 */
@Named(value = "modelerdpMBean")
@SessionScoped
public class ModelerdpMBean implements Serializable {

  
   String variable;
    @EJB
    private RdPManager rdpManager;
   Modelerdp modelerdp;
    
   static Modelerdp modele1;
    
    @EJB
    private Users users;
     

    public ModelerdpMBean() {
    }

    
  public Converter getLoginConverter() {
        return loginConverter;
    }
  
     public List<SelectItem> getAllLogin() {
        List<SelectItem> options = new ArrayList<SelectItem>();
        List<Utilisateur> lu = users.GetAllUsers();
        for (Utilisateur u : lu) {
            options.add(new SelectItem(u, loginConverter.getAsString(null, null, u)));
        }
        return options;
    }
 
    private Converter loginConverter = new Converter() {

        @Override
        public Object getAsObject(FacesContext context, UIComponent component, String login) {

            Utilisateur u = users.getLoginFromUser(login);
            return u;
        }

        @Override
        public String getAsString(FacesContext context, UIComponent component, Object value) {
            Utilisateur u = (Utilisateur) value;
            return u.getLogin()+"";
        }
    };
 

    public List<Modelerdp> getModelerdp() {

        return rdpManager.getAllRdpModels();
    }

    public Modelerdp getDetails() {
        return modelerdp;
    }

    public String showDetails(Modelerdp modelerdp) {
        this.modelerdp = modelerdp;
        return "ModelDetails";
    }

    public String update() {
        System.out.println("###UPDATE###");
        modelerdp = rdpManager.update(modelerdp);
        return "ModeleRDP";
    }

    public String list() {
        System.out.println("###LIST###");
        return "ModeleRDP";
    }
     public String listMarquage() {
        System.out.println("###LIST###");
        return "Marquage";
    }
    public String creeRDP() {
        return "AjouterRDP";
    }
    public String doDeleteModel() {
        rdpManager.remove(modelerdp);
        return "ModeleRDP";
    }
  
  public String byIdm(Modelerdp modele1) {
        this.modele1 = modele1;
        return "Marquage";  
    }
  public String draw(Modelerdp modelerdp) {
      this.modelerdp = modelerdp;
      return "draw";
  }
     
}
